<?php
define('SMARTY_DIR', '/var/www/lib/smarty3129/libs/');
include_once('./util.php');
require_once(SMARTY_DIR . 'Smarty.class.php');

class View extends Smarty {
    
    public function __construct() {
        parent::__construct();

        $this->setTemplateDir('/var/www/html/lpam/templates/');
        $this->setCompileDir('/var/www/html/lpam/templates_c/');
        $this->setConfigDir('/var/www/html/lpam/configs/');
        $this->setCacheDir('/var/www/html/lpam/cache/');
    }
}


// prettyDump(gd_info());

$regDate = new DateTime(date("Y-m-d H:i:s", time()));
$dateZone = new DateTimeZone('Asia/Shanghai');

// prettyDump($dateZone->getTransitions());
/*
echo '<br />';
echo $regDate->getTimestamp();
$regDate->modify('+1days');
echo '<br />';
echo $regDate->getTimestamp();
$regDate->setDate(2016,5,16);
echo '<br />';
echo $regDate->getTimestamp();
$regDate->setDate(2016,5,16);
$regDate->setTime(10,56);
echo '<br />';
echo $regDate->getTimestamp();
$regDate->setTimeZone(new DateTimezone('Asia/Shanghai'));
echo '<br />';
$regDate->getTimezone();

$dir = dir('./');
var_dump($dir);
 */

$dsn = "mysql:host=localhost;dbname=test";
$dbuser = "root";
$dbpass = "snriud";

$dbh = new PDO($dsn, $dbuser, $dbpass);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

try {
    $sql = 'select id, name, add_date from members';
    $stmt = $dbh->prepare($sql);
    $stmt->execute();
    $result = $stmt->fetchAll(PDO::FETCH_ASSOC);

    $addDate = new DateTime('now', new DateTimezone('Asia/Shanghai'));

    $data = array (
        array(
            'id' => null,
            'name' => 'koala',
            'addDate' => $addDate->format('Y-m-d H:i:s')
        ),
        
        array (
            'id' => null,
            'name' => 'panda',
            'addDate' => $addDate->format('Y-m-d H:i:s')
        )
    );

    /*
    foreach ($data as $d) {
        $id = $d['id'];
        $name = $d['name'];
        $ctime = $d['addDate'];

        $stmt->bindParam(':id', $id, PDO::PARAM_NULL);
        $stmt->bindParam(':name', $name, PDO::PARAM_STR);
        $stmt->bindParam(':adddate', $ctime, PDO::PARAM_STR);

        $stmt->execute();
    }
     */

} catch (PDOException $e) {
    preEcho($e->getMessage());
    preEcho($e->getLine());
    preEcho($e->getCode());
    preEcho($e->getTraceAsString());
}

$v = new View();
// $v->assign('users', $result);
// $v->display('index.tpl');

?>

<form action="upload.php" method="post" enctype="multipart/form-data">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    <input type="file" name="userfile"/>
    <input type="submit" value="Send File"/>
</form>
